package iut.acy.cut4u.model;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

public class GregorianDateString {

	public static DateFormat formatDate = DateFormat.getDateInstance(
			DateFormat.SHORT, Locale.FRANCE);

	public static String gregorianToString(GregorianCalendar gdate) {
		final String str = GregorianDateString.formatDate.format(gdate
				.getTime());
		return str;
	}

	public static GregorianCalendar stringToGregorianCalendar(String sdate) {
		if (sdate == null) {
			return null;
		}
		if (sdate.equals("")) {
			return null;
		}

		final GregorianCalendar gdate = new GregorianCalendar();
		boolean dateOK = false;
		Date date;
		try {
			date = GregorianDateString.formatDate.parse(sdate);
			gdate.setTime(date);
			dateOK = true;
		} catch (final ParseException e) {

			System.out.println(e);
		}
		if (dateOK == true) {
			return gdate;
		} else {
			return null;
		}
	}

}
